<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .box{
        width: 100px;height: 100px;
    }
</style>
<body>
    <div id="app">
        <father></father>
    </div>

    <template id="father">
        <div class="father">
            <input type="text" v-model="sky">
            <hr>
            <son :sky="sky"></son>
        </div>
    </template>

    <template id="son">
        <div class="son">
            <input type="text" v-model="color">
            <div class="box" :style="{background: owncolor}"></div>
        </div>
    </template>
</body>
<script src="./base/vue.js"></script>

<script>
    //父组件可以通过v-bind来为子组件传递数据，当父组件的数据改变的时候，
    //子组件接收到的数据也会改变
    new Vue({
        el:"#app",
        components:{
            father:{
                template:"#father",
                data(){
                    return {
                        sky:"sky"
                    }
                },
                components:{
                    son:{
                        template:"#son", 
                        props:["sky"],
                        data(){
                            return {
                                color:"blue"
                            }
                        },
                        computed:{
                            owncolor(){
                                return this.sky+this.color; //"hotpink"
                            }
                        }
                    }
                }
            }
        }
    })
    
    

</script>
</html>